/*
 * vhttp.h
 *
 *  Created on: Apr 24, 2011
 *      Author: xrose
 */

#ifndef HTTPCONNECTION_H_
#define HTTPCONNECTION_H_

#include "incdefault.h"
#include "Net/Socket.h"
#include "Util/Util.h"
#include "Url.h"
#include "thrdStruct.h"

class httpConnections {
private:
	/**
	 * method
	 */
	string createGetRequest();					//create request for sendGet()
	string createGetRangeRequest(int stByte, int endByte);				//create request for senGetRange()
	string createHeadRequest();					//create request for head()
	/**
	 * field
	 */
	int _id;
	Url _url;
	Socket _socket;
	pthread_mutex_t _mutex;
public:
	httpConnections():_id(), _url(), _socket(){pthread_mutex_init(&_mutex, NULL);}
	httpConnections(int id, Url url):_id(id), _url(url), _socket(){pthread_mutex_init(&_mutex, NULL);}
	virtual ~httpConnections(){_socket.close();}
	/**
	 * method: sendGet() - send GET command to download target file
	 */
	bool sendGet();
	/**
	 * method: sendGetRange() - send GET command with specific starting position of download file
	 */
	bool sendGetRange(ulong stByte, ulong endByte);
	/**
	 * methor getHead()
	 */
	string getHead();
	/**
	 * methor: receiveData()
	 */
	int receiveData(thrdStruct &infThread);
	/**
	 * method: close()
	 */
	bool close();
};

#endif /* HTTPCONNECTION_H_ */
